/*
 *  Copyright (C) 2010 Glauco
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.balisunrise.swing.components.panel;

import java.awt.Dimension;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import org.balisunrise.application.Application;
import org.balisunrise.common.IconManager;
import org.balisunrise.common.PropertiesReader;
import org.balisunrise.swing.components.panel.layouts.SearchLayoutBuilder;

/**
 *
 * @author Glauco
 */
public class SelectionPanel extends JPanel{

    private JPanel gridPanel;
    private JPanel actionPanel;
    private JPanel messagePanel;

    private SearchLayoutBuilder layoutBuilder;

    public JPanel getActionPanel() {
        return actionPanel;
    }

    public void setActionPanel(JPanel actionPanel) {
        this.actionPanel = actionPanel;
    }

    public JPanel getGridPanel() {
        return gridPanel;
    }

    public void setGridPanel(JPanel gridPanel) {
        this.gridPanel = gridPanel;
    }

    public LayoutBuilder getLayoutBuilder() {
        return layoutBuilder;
    }

    public void setLayoutBuilder(SearchLayoutBuilder layoutBuilder) {
        this.layoutBuilder = layoutBuilder;
    }

    public SelectionPanel(JPanel gridPanel, JPanel actionPanel,
            SearchLayoutBuilder layoutBuilder) {

        super();

        this.gridPanel = gridPanel;
        this.actionPanel = actionPanel;

        setMinimumSize(new Dimension(10, 315));
        setBorder(BorderFactory.createEtchedBorder());

        PropertiesReader pr = Application.get().getPropertiesReader();
        IconManager<ImageIcon> im = Application.get().getIconManager();

        messagePanel = new JPanel();
        JLabel label = new JLabel(pr.readProperty(pr.selectOneEntity),
                im.getIcon(im.WARNING),
                SwingConstants.LEFT);
        messagePanel.add(label);

        this.layoutBuilder = layoutBuilder;

        createLayout();
    }

    private void createLayout(){

        layoutBuilder.setActionPanel(actionPanel);
        layoutBuilder.setFilterPanel(messagePanel);
        layoutBuilder.setGridPanel(gridPanel);
        
        layoutBuilder.buildLayout(this);

    }
}
